package com.example.demo.common;

import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;

import com.example.demo.service.UserServiceImpl;

/**
 * @Description kafka test
 * @ClassName KafkaConsumer
 * @Author: jinqi.zhu
 * @Create: 2021/8/17 11:17
 */
@Component
public class KafkaConsumer {
    private static final Logger logger = LoggerFactory.getLogger(UserServiceImpl.class);

    /**
     * 功能描述: 消费方法
     *
     * @Author jinqi.zhu
     * @Date 2021/8/17 11:11
     */
    @KafkaListener(topics = {"topic1"}, groupId = "user-log-group")
    public void onMessage1(ConsumerRecord<?, ?> record) {

        // 消费的哪个topic、partition的消息,打印出消息内容
        logger.info("简单消费：" + record.topic() + "-" + record.partition() + "-" + record.value());
    }
}